// pages/user/detailLeader/index.js
import urls from '../../../requestUrl.js'
import request from '../../../baseRequest.js'
Page({

    /**
     * 页面的初始数据
     */
    data: {
        showBottomPop: false,
        info: {}
    },
    /**获取救援公司负责人信息 */
    getLeaderInfo() {
        let param = {
            'openid': this.data.openid
        }
        request.postRequest(urls.leader.getLeaderInfo, param, (res) => {
            console.log('负责人信息：', res)
            console.log(res)
            let info = res
            let businessLicense = []
            if (info.businessLicense) businessLicense.push(info.businessLicense)
            info.businessLicense = businessLicense
            let applicants = []
            if (info.applicants) applicants.push(info.applicants)
            info.applicants = applicants
            let companyLogo = []
            if (info.companyLogo) companyLogo.push(info.companyLogo)
            info.companyLogo = companyLogo
            info.companyRegion = info.companyRegion ? info.companyRegion.split(',') : null
            this.setData({
                info: info
            })
        }, () => {})
    },
    /**前往修改页面 */
    handleToEditInfo() {
        wx.navigateTo({
            url: '/pages/user/registerLeader/index?type=2',
        })
    },
    /**
     * 打开底部弹出层-修改公司名称
     * @param {*} e 
     */
    handleToShowBottomPop(e) {
        console.log(e)
        if (this.data.info.auditStatus == 2) {
            this.setData({
                showBottomPop: true
            })
        }

    },
    /**
     * 关闭底部弹出层-修改公司名称
     * @param {*} e 
     */
    handleToHideBottomPop(e) {
        this.setData({
            showBottomPop: false
        })
    },
    /**
     * 提交修改公司名称
     * @param {*} e 
     */
    handleSubmitChangeCompanyName(e) {
        wx.showModal({
            title: '温馨提示',
            content: '是否确认修改当前公司名称？',
            success: res => {
                if (res.confirm) {
                    let param = e.detail.value
                    param.openid = this.data.openid
                    request.postRequest(urls.leader.editCompanyName, param, (res) => {
                        wx.showToast({
                            icon: 'none',
                            title: '修改成功',
                            complete: () => {
                                this.getLeaderInfo() //刷新当前页面信息
                                this.setData({
                                    showBottomPop: false
                                })
                            }
                        })
                    }, () => {})
                }
            }
        })
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function(options) {
        this.data.openid = getApp().getUserOpenid()
    },

    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady: function() {

    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow: function() {
        this.getLeaderInfo()
    },

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide: function() {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload: function() {

    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh: function() {

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom: function() {

    },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage: function() {

    }
})